<!--项目详情-计划-->
<template>
  <PiTable
    :tableData
    :tableColumns
    :pagination="page"
    @pageChange="pageChange"
    @confirmSetting="getData"
  >
    <template #icon>
      <el-icon><Setting /></el-icon>
    </template>
    <template #name="{ row }">
      <el-link type="primary" v-jump.open="['planDetail', { oid: row.oid, title: `${row.name}` }]">
        {{ row.name }}
      </el-link>
    </template>
  </PiTable>
</template>

<script setup>
const route = useRoute();
const loading = ref(false);
const tableColumns = ref([]);
const tableData = ref([]);
const { projectListApi } = window.$api;
const page = reactive({
  pageNum: 1, //当前页
  pageSize: 10, //每页数
  total: 0, //数据总量
});
const param = {
  tableID: 'ProjectTable',
  softType: 'com.pisx.pmgt.project.PIProject',
};
const settingColumns = {
  getColumns: projectListApi.setProjectTableColumns, //获取表头接口
  getColumnsParams: param, //接口入参
  setColumns: projectListApi.saveProjectTableColumns, //保存设置的表头接口
  setColumnsParams: param, //接口入参
};

onMounted(() => {
  getData();
});

/**
 * 获取表格数据
 * */
const getData = () => {
  loading.value = true;
  const params = {
    tableID: 'ProjectPlanTable',
    oid: route.query.oid,
    page: page.pageNum,
    range: page.pageSize,
  };

  window.$api.projectListApi
    .findPlans(params)
    .then((res) => {
      tableColumns.value = [
        {
          prop: 'icon',
          label: '',
          width: 40,
        },
        ...res.data.columns.map((item) => ({ ...item, sortable: true })),
      ];
      tableData.value = res.data.rows;
      page.total = res.data.total;
    })
    .finally(() => {
      loading.value = false;
    });
};
/**
 * 分页
 * @pageNum {number} 当前页码
 * @pageSize {number} 每页显示数
 * */
const pageChange = (pageNum, pageSize) => {
  page.pageNum = pageNum;
  page.pageSize = pageSize;
  getData();
};
</script>

<style scoped lang="less"></style>
